package com.smh.genericity.fanxingInterface;

/**
 * @description: 泛型接口实现类
 * @author: shenmhk
 * @create: 2020-10-21 13:15
 */

import java.util.ArrayList;
import java.util.List;

/**
 * 在声明类的时候，需将泛型的声明也一起加到类中，即：class FruitGenerator<T> implements Generator<T>
 * @param <T>
 */
public class FruitGenerator<T> implements Generator<T> {

    public T next() {
        return null;
    }

    public void test(List c) {
        for(int i=0;i<c.size();i++) {
            System.out.println(c.get(i));
        }
    }

    public void test1(List<?> c){
        List<?> c1 = new ArrayList<String>();
        for (int i = 0; i < c.size(); i++) {
            System.out.println(c.get(i));
        }
    }

}

/**
 * 如果不声明泛型，如：class FruitGenerator implements Generator<T>，编译器会报错："Unknown class"
  */
//public class FruitGenerator implements Generator<T>{
//
//    public T next() {
//        return null;
//    }
//}

//public class FruitGenerator implements Generator<String>{
//
//    public String next() {
//        return null;
//    }
//}